{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ngRWPuICNIOD"
      },
      "outputs": [],
      "source": [
        "!pip install langchain-tensorlake"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%env TENSORLAKE_API_KEY=your_tensorlake_api_key\n",
        "\n",
        "# In this example, we use OpenAI's GPT-4o-mini model.\n",
        "%env OPENAI_API_KEY=your_openai_api_key"
      ],
      "metadata": {
        "id": "8tuRP00aNWwF"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# 1. Import the langchain-tensorlake tool and other necessary libraries\n",
        "from langchain_tensorlake import DocumentParserOptions, document_markdown_tool\n",
        "from langgraph.prebuilt import create_react_agent\n",
        "import os\n",
        "\n",
        "# 2. Define the document path\n",
        "path= \"https://pub-226479de18b2493f96b64c6674705dd8.r2.dev/real-estate-purchase-all-signed.pdf\"\n",
        "\n",
        "# 3. Define the question to be asked and create the agent\n",
        "question = f\"What contextual information can you extract about the signatures in my document found at {path}?\"\n",
        "\n",
        "# 4. Create the agent with the Tensorlake tool\n",
        "agent = create_react_agent(\n",
        "    model=\"openai:gpt-4o-mini\",\n",
        "    tools=[document_markdown_tool],\n",
        "    prompt=(\n",
        "        \"\"\"\n",
        "        I have a document that needs to be parsed. Please parse this document and answer the question about it.\n",
        "        \"\"\"\n",
        "    ),\n",
        "    name=\"real-estate-agent\",\n",
        ")\n",
        "\n",
        "# 5. Run the agent\n",
        "result = agent.invoke({\"messages\": [{\"role\": \"user\", \"content\": question}]})\n",
        "\n",
        "# 6. Print the result\n",
        "print(result[\"messages\"][-1].content)"
      ],
      "metadata": {
        "id": "341H7AdfNgrd"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}